module FluentAttrs
  def attrs(**opts)
    opts.each {|name, default| define_attr(name, default)}
  end

  def define_attr(name, default)
    class_eval do
      define_method(name) do |*value|
        if value.size > 0
          instance_variable_set(:"@#{name}", value[0])
        else
          instance_variable_get(:"@#{name}") || default
        end
      end
    end
  end
end
